package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.MerInfo;
import com.ruoyi.web.service.IMerInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商户信息Controller
 * 
 * @author ruoyi
 * @date 2021-04-04
 */
@Controller
@RequestMapping("/pay/info")
public class MerInfoController extends BaseController
{
    private String prefix = "pay/info";

    @Autowired
    private IMerInfoService merInfoService;

    @RequiresPermissions("pay:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询商户信息列表
     */
    @RequiresPermissions("pay:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MerInfo merInfo)
    {
        startPage();
        List<MerInfo> list = merInfoService.selectMerInfoList(merInfo);
        return getDataTable(list);
    }

    /**
     * 导出商户信息列表
     */
    @RequiresPermissions("pay:info:export")
    @Log(title = "商户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerInfo merInfo)
    {
        List<MerInfo> list = merInfoService.selectMerInfoList(merInfo);
        ExcelUtil<MerInfo> util = new ExcelUtil<MerInfo>(MerInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增商户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商户信息
     */
    @RequiresPermissions("pay:info:add")
    @Log(title = "商户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MerInfo merInfo) throws Exception
    {
        return toAjax(merInfoService.insertMerInfo(merInfo));
    }

    /**
     * 修改商户信息
     */
    @GetMapping("/edit/{merchCd}")
    public String edit(@PathVariable("merchCd") String merchCd, ModelMap mmap)
    {
        MerInfo merInfo = merInfoService.selectMerInfoById(merchCd);
        mmap.put("merInfo", merInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存商户信息
     */
    @RequiresPermissions("pay:info:edit")
    @Log(title = "商户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MerInfo merInfo) throws Exception
    {
        return toAjax(merInfoService.updateMerInfo(merInfo)) ;
    }

    /**
     * 删除商户信息
     */
    @RequiresPermissions("pay:info:remove")
    @Log(title = "商户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(merInfoService.deleteMerInfoByIds(ids));
    }
}
